<template>
	<view>
		我是test
		<button @click="getUFood">获取个人常常吃的数据</button>
	</view>
</template>

<script>
	export default {
		data() 
		{
			return {
				
			}
		},
		methods: {
			async getUFood()
			{
				console.log(11111111111);
				//查询用户吃的数据
				let res = await this.$u.api.getUserFood({id:this.vuex_token.openid})
				
				//数据存入数组中备用
				let arr = [
						res.bDecoct,  //煎 0
						res.bFry,	//炒 1
						res.bMeat,	//肉 2
						res.bPlain,	//菜 3
						res.bSour,	//酸 4
						res.bSpicy,	//辣 5
						res.bSweet	//甜 6
					];
				//复制数组
				let newArr = [...arr]
				//对新数组排序
				newArr = newArr.sort((a,b) => {return b-a})
				
				//准备前三的变量
				let maxOne = 0
				let maxTwo = 0
				let maxThree = 0
				
				//遍历赋值前三排行版
				for (let i = 0;i < arr.length;i++) 
				{
					if(newArr[0] === arr[i])
					{
						maxOne = i
					} 
					if(newArr[1] === arr[i])
					{
						maxTwo = i
					} 
					if(newArr[2] === arr[i])
					{
						maxThree = i
					} 
				}
				console.log(maxOne,maxTwo,maxThree);
				
				//准备提交的params
				let params = {
					tDecoct:0,  //煎 0
					tFry:0,	//炒 1
					tMeat:0,	//肉 2
					tPlain:0,	//菜 3
					tSour:0,	//酸 4
					tSpicy:0,	//辣 5
					tSweet:0	//甜 6
				}
				
				//把前三映射入params中
				let mid = 0
				for (let key in params) 
				{
					if(mid === maxOne)
					{
						params[key] = 1
					}
					if(mid === maxTwo)
					{
						params[key] = 1
					}
					if(mid === maxThree)
					{
						params[key] = 1
					}
					mid ++
				}
				
				console.log(params)
				res = await this.$u.api.getLikeFood(params)
				console.log(res);
			}
		}
	}
</script>

<style>

</style>
